﻿package net.wangit.framework.config;

import net.wangit.Path;
import net.wangit.util.FileUtil;
import net.wangit.util.XMLUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Element;


/**
 * 向导设置
 * 
 * @author watson
 * 
 */
public class WizardSettings {
	private static final Log log = LogFactory.getLog(WizardSettings.class);
	public final static String FILE_NAME = "wizard.xml";
	private static WizardSettings instance;

	// 表单单元
	private static String formColumn; // 列数
	private static String formColsConfig; // 列配置
	private static String formShowUnitBorder;// 显示单元边框
	private static String formShowTitleBorder;// 显示标题区边框
	private static String formShowGridBorder;// 显示主体区边框
	private static String formShowCellBorder;// 显示TD边框

	// 列表单元
	private static String listShowUnitBorder;// 显示单元边框
	private static String listShowTitleBorder;// 显示标题区边框
	private static String listShowGridBorder;// 显示主体区边框
	private static String listShowCellBorder;// 显示TD边框

	// 查询单元
	private static String queryColumn;// 列数
	private static String queryColsConfig;// 列配置
	private static String queryShowUnitBorder;// 显示单元边框
	private static String queryShowTitleBorder;// 显示标题区边框
	private static String queryShowGridBorder;// 显示主体区边框
	private static String queryShowCellBorder;// 显示TD边框

	private WizardSettings() {
	}

	public static WizardSettings instance() {
		if (instance == null) {
			instance = new WizardSettings();
			instance.loadDefault();
		}
		return instance;
	}

	public void loadDefault() {
		formColumn = "4";
		formColsConfig = "RC,15%,1;LC,35%,1;RC,15%,1;LC,35%,1;";
		formShowUnitBorder = "0";
		formShowTitleBorder = "1";
		formShowGridBorder = "1";
		formShowCellBorder = "0";

		listShowUnitBorder = "0";
		listShowTitleBorder = "1";
		listShowGridBorder = "1";
		listShowCellBorder = "0";

		queryColumn = "4";
		queryColsConfig = "RC,15%,1;LC,35%,1;RC,15%,1;LC,35%,1;";
		queryShowUnitBorder = "0";
		queryShowTitleBorder = "1";
		queryShowGridBorder = "1";
		queryShowCellBorder = "0";
	}

	public void load() {
		String path = Path.getConfigPath(FILE_NAME);
		if (FileUtil.exists(path)) {
			Document document = XMLUtil.parseByPath(path);
			Element root = document.getRootElement();
			formColumn = XMLUtil.getTextString(root, "formColumn", "4");
			formColsConfig = XMLUtil.getTextString(root, "formColsConfig",
					"RC,15%,1;LC,35%,1;RC,15%,1;LC,35%,1;");
			formShowUnitBorder = XMLUtil.getTextString(root,
					"formShowUnitBorder", "0");
			formShowTitleBorder = XMLUtil.getTextString(root,
					"formShowTitleBorder", "1");
			formShowGridBorder = XMLUtil.getTextString(root,
					"formShowGridBorder", "1");
			formShowCellBorder = XMLUtil.getTextString(root,
					"formShowCellBorder", "0");
			listShowUnitBorder = XMLUtil.getTextString(root,
					"listShowUnitBorder", "0");
			listShowTitleBorder = XMLUtil.getTextString(root,
					"listShowTitleBorder", "1");
			listShowGridBorder = XMLUtil.getTextString(root,
					"listShowGridBorder", "1");
			listShowCellBorder = XMLUtil.getTextString(root,
					"listShowCellBorder", "0");
			queryColumn = XMLUtil.getTextString(root, "queryColumn", "4");
			queryColsConfig = XMLUtil.getTextString(root, "queryColsConfig",
					"RC,15%,1;LC,35%,1;RC,15%,1;LC,35%,1;");
			queryShowUnitBorder = XMLUtil.getTextString(root,
					"queryShowUnitBorder", "0");
			queryShowTitleBorder = XMLUtil.getTextString(root,
					"queryShowTitleBorder", "1");
			queryShowGridBorder = XMLUtil.getTextString(root,
					"queryShowGridBorder", "1");
			queryShowCellBorder = XMLUtil.getTextString(root,
					"queryShowCellBorder", "0");
			log.info("load wizard settings successfully.");
		} else {
			loadDefault();
		}
	}

	public String getFormColsConfig() {
		return formColsConfig;
	}

	public String getFormColumn() {
		return formColumn;
	}

	public String getFormShowCellBorder() {
		return formShowCellBorder;
	}

	public String getFormShowGridBorder() {
		return formShowGridBorder;
	}

	public String getFormShowTitleBorder() {
		return formShowTitleBorder;
	}

	public String getFormShowUnitBorder() {
		return formShowUnitBorder;
	}

	public String getListShowCellBorder() {
		return listShowCellBorder;
	}

	public String getListShowGridBorder() {
		return listShowGridBorder;
	}

	public String getListShowTitleBorder() {
		return listShowTitleBorder;
	}

	public String getListShowUnitBorder() {
		return listShowUnitBorder;
	}

	public String getQueryColsConfig() {
		return queryColsConfig;
	}

	public String getQueryColumn() {
		return queryColumn;
	}

	public String getQueryShowCellBorder() {
		return queryShowCellBorder;
	}

	public String getQueryShowGridBorder() {
		return queryShowGridBorder;
	}

	public String getQueryShowTitleBorder() {
		return queryShowTitleBorder;
	}

	public String getQueryShowUnitBorder() {
		return queryShowUnitBorder;
	}
}
